using System;
using System.IO;

namespace Pegasus.Diagnostics.Telnet
{
	/// <summary>
	/// Implements the Quit command for the telnet service
	/// </summary>
	internal class CommandQuit : ITelnetCommand
	{
		// Local Instanc Values
		private TelnetProcessor m_processor;

		/// <summary>
		/// Default Constructor
		/// </summary>
		/// <param name="processor">The telnet process handing this session</param>
		public CommandQuit( TelnetProcessor processor )
		{
			m_processor = processor;
		}

		/// <summary>
		/// The names of the command that the user types in.
		/// </summary>
		public string Command
		{
			get
			{
				return "quit";
			}
		}

		/// <summary>
		/// Any short cut commands or key (i.e. quit uses q and exit)
		/// </summary>
		public string[] CommandShortCuts
		{
			get
			{
				return new string[] { "q", "exit" };
			}
		}

		/// <summary>
		/// Execute the command.
		/// </summary>
		/// <param name="args">Additional parameters that the user typed in.</param>
		/// <param name="writer">Text stream to write to</param>
		public void ExecCommand( TextWriter writer, string[] args )
		{
			m_processor.Stop();
		}

		/// <summary>
		/// Show a single line of help about the command
		/// </summary>
		/// <returns>Single line brief description of command</returns>
		public string GetHelp()
		{
			return "End the telnet session.";
		}

		/// <summary>
		/// Show a the full usage help about the command
		/// </summary>
		/// <param name="writer">Text stream to write to</param>
		public void ShowDetailedHelp( TextWriter writer )
		{
			writer.WriteLine( "Command: quit | q | exit" );
			writer.WriteLine( "Usage: quit" );
			writer.WriteLine();
			writer.WriteLine( "Description:  This end the current telnet session." );
		}
	}
}
